home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NeXTSTEP 3.3 (Developer)…68k, x86, SPARC, PA-RISC]
/
NeXTSTEP 3.3 Dev Intel.iso
/
NextDeveloper
/
Headers
/
foundation
/
NSNotification.h
< prev
next >
Wrap
Text File
|
1994-05-02
|
3KB
|
81 lines
/* NSNotification.h
Copyright 1993, 1994, NeXT, Inc.
Posting and observing notifications;
NeXT, June 93
*/
#import <foundation/NSDictionary.h>
/* Example of use:
Say you have a port object that is dying and an object (observer) that needs to know about the death of that port.
The observer would initially register as:
[[NSNotificationCenter defaultCenter] addObserver:observer selector:@selector(handlePortDeath:) forNotificationName:@"NSPortInvalid" fromObject:port];
When a port dies, the following code gets executed:
[[NSNotificationCenter defaultCenter] postNotificationName:@"NSPortInvalid" object:port];
The notification center will then perform:
- (void)handlePortDeath:(NSNotification *)notification {
// we know that [port isEqual:[notification object]]
...
}
*/
/*************** Notification ***************/
@interface NSNotification:NSObject <NSCopying>
/* Note that notifications may contain extra information, but then that extra data must be agreed upon between notifiers and observers */
- (NSString *)notificationName;
/* A string denoting the notification such as "NSPPLChanged" or "NSPortInvalid" */
- notificationObject;
/* The object of the notification; often is the object that posted a notification about itself;
may be nil */
+ allocWithZone:(NSZone *)zone;
/* Creates an instance of a concrete class (substitutes a concrete class if called with NSNotification) */
+ (NSNotification *)notificationWithName:(NSString *)name object:object;
/* copies name; retains object */
@end
/*************** Notification Center ***************/
@interface NSNotificationCenter:NSObject {
id _lock;
NSMutableDictionary *_registry;
id _noNotificationNameRegistry;
}
+ (NSNotificationCenter *)defaultCenter;
/* a per-task notification center used for generic notifications */
- (void)postNotification:(NSNotification *)notification;
- (void)addObserver:observer selector:(SEL)selector notificationName:(NSString *)notificationName object:object;
/* observer will perform selector with the notification as argument when notification with given name from given object is posted;
observer is not retained which implies that removeObserver: must be called prior to invalidating the observer;
If object is nil, observer will get posted whatever the object was;
object (when non-nil) is not retained by the notification center which implies that removeObserver: must be called prior to invalidating the object;
object identity is pointer equality;
If notificationName is nil, observer will get posted whatever for all notifications that match object */
- (void)removeObserver:observer notificationName:(NSString *)notificationName object:object;
/* This method will remove all observers with same notificationName and same object (even when object is nil) */
- (void)removeObserver:observer;
/* Removes all the observations of observer;
Relativly slow (goes over all tables) */
- (void)postNotificationName:(NSString *)notificationName object:object;
/* Short cut for posting an notification */
@end